package com.haoma.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoma.entity.AboutMe;
import com.haoma.entity.LearningPath;
import com.haoma.entity.Technology;
import com.haoma.mapper.AboutMeMapper;
import com.haoma.mapper.LearningPathMapper;
import com.haoma.mapper.TechnologyMapper;
import com.haoma.service.AboutMeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Description:
 */
@Service
public class AboutMeServiceImpl extends ServiceImpl<AboutMeMapper, AboutMe> implements AboutMeService {


    @Autowired
    private TechnologyMapper technologyMapper;

    /**
     * 获取关于我的信息
     *
     * @return
     */
    public AboutMe getAboutMe() {
        AboutMe aboutMe = getById(1);
        List<Technology> technologies = technologyMapper.selectList(new LambdaQueryWrapper<>());
        if (!CollectionUtils.isEmpty(technologies)) {
            aboutMe.setTechnology(technologies);
        }
        return aboutMe;
    }

    @Autowired
    private LearningPathMapper learningPathMapper;

    /**
     * 获取学习路
     *
     * @return
     */
    public List<LearningPath> getLearningPath() {
        LambdaQueryWrapper<LearningPath> learningPathLambdaQueryWrapper = new LambdaQueryWrapper<>();
        learningPathLambdaQueryWrapper.orderByAsc(LearningPath::getStartTime);
        List<LearningPath> learningPaths = learningPathMapper.selectList(learningPathLambdaQueryWrapper);
        return learningPaths;
    }

}
